package com.example.fresheveryday.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.fresheveryday.po.Shopcart;
import com.example.fresheveryday.po.Userreceiveinfo;
import com.example.fresheveryday.restful.JsonResult;
import com.example.fresheveryday.service.UserreceiveinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ll
 * @since 2023-07-5
 */
@RestController
@RequestMapping("/userreceiveinfo")
public class UserreceiveinfoController {
    @Autowired
    UserreceiveinfoService userreceiveinfoService;
    @RequestMapping("/insert")
    public String insert(Userreceiveinfo userreceiveinfo){
        userreceiveinfoService.save(userreceiveinfo);
        return "success";
    }
    @RequestMapping("/myReceive")
    public List<Userreceiveinfo> list(@RequestBody Map<String,Object> map){
        String id = map.get("id").toString();
        System.out.println(id);
        QueryWrapper<Userreceiveinfo> wrapper = new QueryWrapper<>();
        wrapper.eq("userId",id);
        return userreceiveinfoService.list(wrapper);
    }
    @RequestMapping("/delete")
    public JsonResult delete(String id){
        userreceiveinfoService.removeById(id);
        return JsonResult.success("success");
    }
    @RequestMapping("/update")
    public String update(Userreceiveinfo userreceiveinfo){
        QueryWrapper<Userreceiveinfo> wrapper = new QueryWrapper<>();
        wrapper.eq("id",userreceiveinfo.getId());
        userreceiveinfoService.update(wrapper);
        return "success";
    }

}
